import { request } from '@umijs/max';

export async function add(
  data: {
    name?: any;
    parentId?: any;
    sort?: any;
    level?: any;
  },
  options?: { [key: string]: any },
) {
  return request<{
    code: number;
    data: Record<string, any>;
    msg?: string;
  }>('/product-server/api/v1/categories/save', {
    method: 'POST',
    data,
    ...(options || {}),
  });
}

export async function update(
  data: {
    name?: any;
    parentId?: any;
    level?: any;
    sort?: any;
  },
  options?: { [key: string]: any },
) {
  return request<{
    code: number;
    data: Record<string, any>;
    msg?: string;
  }>('/product-server/api/v1/categories/update', {
    method: 'PUT',
    data,
    ...(options || {}),
  });
}

export async function batchUpdate(
  data: {
    name?: any;
    parentId?: any;
    level?: any;
    sort?: any;
  },
  options?: { [key: string]: any },
) {
  return request<{
    code: number;
    data: Record<string, any>;
    msg?: string;
  }>('/product-server/api/v1/categories/batch_update', {
    method: 'PUT',
    data,
    ...(options || {}),
  });
}

export async function treeUpdate(
  data: any[],
  options?: { [key: string]: any },
) {
  return request<{
    code: number;
    data: Record<string, any>;
    msg?: string;
  }>('/product-server/api/v1/categories/update_tree', {
    method: 'PUT',
    data,
    ...(options || {}),
  });
}

export async function del(
  data: {
    idList?: any;
  },
  options?: { [key: string]: any },
) {
  return request<{
    code: number;
    data: Record<string, any>;
    msg?: string;
  }>('/product-server/api/v1/categories/batch_del', {
    method: 'DELETE',
    data,
    ...(options || {}),
  });
}

export async function list(
  data: {
    name?: any;
    parentId?: any;
    level?: any;
  },
  options?: { [key: string]: any },
) {
  return request<{
    code: number;
    data: Record<string, any>[];
    msg?: string;
  }>('/product-server/api/v1/categories/list', {
    method: 'POST',
    data,
    ...(options || {}),
  });
}

export async function findIdsTree(
  data: {
    id: any
  },
  options?: { [key: string]: any },
) {
  return request<{
    code: number;
    data: Record<string, any>;
    msg?: string;
  }>('/product-server/api/v1/categories/find_tree', {
    method: 'POST',
    data,
    ...(options || {}),
  });
}

export async function upload(
  data: FormData,
  options?: { [key: string]: any },
) {
  return request<{
    code: number;
    data: Record<string, any>;
    msg?: string;
  }>('/product-server/api/v1/file/upload', {
    method: 'POST',
    data,
    ...(options || {}),
  });
}

export async function batchUpload(
  data: FormData,
  options?: { [key: string]: any },
) {
  return request<{
    code: number;
    data: string;
    msg?: string;
  }>('/product-server/api/v1/file/batch_upload', {
    method: 'POST',
    data,
    ...(options || {}),
  });
}
